package com.aistar.controller;

import com.aistar.model.bo.Result;
import com.aistar.model.entity.Employee;
import com.aistar.service.job.IDeliveryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @ClassName: DeliveryRestController
 * @author: LiuWenXiu
 * @date: 2021/10/28 18:46
 * @Description: TODO...本类用来演示: 简历投递控制层
 */
@RestController
@RequestMapping("/job")
public class DeliveryRestController {

    @Autowired
    private IDeliveryService deliveryService;

    // 投递简历
    @GetMapping("/delivery")
    public Result delivery(HttpServletRequest request, Integer resumeId, Integer recruitmentId){
        HttpSession session=request.getSession();
        Employee employee= (Employee) session.getAttribute("employee");
        Integer employeeId = employee.getId();
//        System.out.println("求职者id:"+employeeId);

        // 首先判断该用户是否被屏蔽
        boolean judge = deliveryService.judgeBlacklist(recruitmentId,employeeId);
        if(judge){
            return new Result("502","sorry,您没有权限");
        }


        // 否则表示没有被屏蔽,进行判断是否可以投递
        // 判断是否可以进行投递
        boolean flag = deliveryService.judgeDelivery(recruitmentId,employeeId);

        // 如果可以投递,则往redis里插数据
        if(flag){
            deliveryService.saveToRedis(resumeId,recruitmentId,employeeId);
            return new Result("200","投递成功");
        }

        // 如果不可以投递,则直接返回不行
        return new Result("501","三个月内仅可以投递一次");
    }

}
